package com.hxd.otc.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.hxd.otc.R;

/**
 * 项  目 :  OrderSupervisor
 * 包  名 :  com.example.administrator.blocksbankclient.widget
 * 类  名 :  BlocksViewPager
 * 作  者 :  胡庆岭
 * 时  间 :  2018/6/1 9:46
 * 描  述 :  ${TODO}
 */
public class BlocksViewPager extends ViewPager {
    public void setSlideViewPager(boolean slideViewPager) {
        isSlideViewPager = slideViewPager;
    }

    private boolean isSlideViewPager = true;

    public BlocksViewPager(@NonNull Context context) {
        super(context);
    }

    public BlocksViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initAttrs(attrs);
    }

    private void initAttrs(AttributeSet attrs) {
        TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.BlocksViewPager);
        if (typedArray != null && typedArray.getIndexCount() > 0) {
            isSlideViewPager = typedArray.getBoolean(R.styleable.BlocksViewPager_is_slider_pager, true);
            typedArray.recycle();
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return isSlideViewPager && super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return !isSlideViewPager || super.onTouchEvent(ev);
    }
}
